//Accepted
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int> pii;
int N, m, a, b, pre[501][501][2], p1, p2;
bool ja[501][501];
vector<int> adj[501], c[2];
vector<int>::iterator it, jt, ie, je;
queue< pii > q;

void read(){
	scanf("%d %d", &N, &m);
	for(int i=0;i<m;i++){
		scanf("%d %d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
}

bool process(){
	pre[1][N][0]=-1;
	pii p(1,N), pp;
	q.push(p);
	
	while(!q.empty()&&pre[N][1][0]==0){
		p = q.front();q.pop();
		p1=p.first;p2=p.second;
		for( it=adj[p1].begin(), ie=adj[p1].end(); it < ie; it++ ){
			if(ja[*it][p2])continue;
			ja[*it][p2]=true;
			for( jt=adj[p2].begin(), je=adj[p2].end(); jt < je; jt++ ){
				if(*it == *jt)continue;
				if(pre[*it][*jt][0]==0){
					pre[*it][*jt][0]=p1;
					pre[*it][*jt][1]=p2;
					pp=make_pair(*it,*jt);
					q.push(pp);
				}
			}
		}
	}
	if(pre[N][1][0]==0)return false;
	
	int x=N, y=1, z;
	while(x>0){
		c[0].push_back(x);
		c[1].push_back(y);
		z=x;
		x = pre[x][y][0];
		y = pre[z][y][1];
	}
	return true;
}
int main(){
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	read();
	if(process()){
		printf("%d\n",c[0].size()-1);
		for(int i=0;i<2;i++){
			for( it=c[i].end()-1, ie=c[i].begin(); it >= ie; it-- )printf("%d ", *it);
			printf("\n");
		}
	}
	else printf("-1");
	return 0;
}
